using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Common.Tools.BusinessLayer;
using System.Data;

namespace Emlyn.Website.Articles
{
    public class xArticleListQuery : BaseQuery<xArticleList, Guid, xArticleListDataLayer>
    {
        public xArticleListQuery()
            : base(new xArticleListDataLayer())
        {
        }

        public xArticleList GetArticleListByArticleListCode(string aArticleListCode)
        {
            return ConstructInstanceFromDataSet(_dl.GetArticleListByArticleListCode(aArticleListCode));
        }

        public IList<Article> GetArticlesForArticleListID(Guid aArticleListID)
        {
            ArticleQuery larticleQuery = new ArticleQuery();

            return larticleQuery.GetArticlesForArticleListID(aArticleListID);
        }

        public IList<xArticleList> GetChildArticleListsForArticleListID(Guid aArticleListID)
        {
            return ConstructInstancesFromDataSet(_dl.GetChildArticleListsByArticleListID(aArticleListID));
        }

        public IList<xArticleList> GetNonChildArticleListsForArticleListID(Guid aArticleListID)
        {
            return ConstructInstancesFromDataSet(_dl.GetNonChildArticleListsByArticleListID(aArticleListID));
        }

        public IList<xArticleList> GetTopLevelArticleLists()
        {
            return ConstructInstancesFromDataSet(_dl.GetTopLevelArticleLists());
        }

        public IList<xArticleList> GetParentArticleListsForArticleListID(Guid aArticleListID)
        {
            return ConstructInstancesFromDataSet(_dl.GetParentArticleListsByArticleListID(aArticleListID));
        }

        public IList<xArticleList> GetNonParentArticleListsForArticleListID(Guid aArticleListID)
        {
            return ConstructInstancesFromDataSet(_dl.GetNonParentArticleListsByArticleListID(aArticleListID));
        }

        protected override xArticleList ConstructInstanceFromRow(DataRow lrow)
        {
            xArticleList larticlelist = new xArticleList((Guid)lrow["ArticleListID"]);
            larticlelist.ArticleListCode = Convert.ToString(lrow["ArticleListCode"]).Trim();
            larticlelist.ArticleListName = Convert.ToString(lrow["ArticleListName"]).Trim();
            larticlelist.ArticleListDescription = Convert.ToString(lrow["ArticleListDescription"]).Trim();
            return larticlelist;
        }
    }
}
